package com.flyco.modules.stm.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.flyco.common.api.vo.Result;
import com.flyco.common.aspect.annotation.AutoLog;
import com.flyco.common.system.base.controller.BaseController;
import com.flyco.common.system.query.QueryGenerator;
import com.flyco.modules.pms.entity.PmsProductCategory;
import com.flyco.modules.stm.entity.StmDistributorGroup;
import com.flyco.modules.stm.entity.StmStoreInfo;
import com.flyco.modules.stm.service.IStmDistributorGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@Api(tags = "经销商分组")
@RestController
@RequestMapping("/f/stm/stmDistributorGroup")
public class StmDistributorGroupController extends BaseController<StmDistributorGroup, IStmDistributorGroupService> {

    @Autowired
    private IStmDistributorGroupService distributorGroupService;


    /**
     * 获取全部有效分组
     */
    @AutoLog(value = "经销商分组-获取全部有效分组")
    @ApiOperation(value = "经销商分组-获取全部有效分组", notes = "经销商分组-获取全部有效分组")
    @PostMapping(value = "/queryGroup")
    public Result<?> queryPageList() {

        LambdaQueryWrapper<StmDistributorGroup> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(StmDistributorGroup::getStatus, 1);
        List<StmDistributorGroup> stmDistributorGroupList = distributorGroupService.list(lambdaQueryWrapper);
        return Result.ok(stmDistributorGroupList);
    }



    /**
     * 分页列表查询
     */
    @AutoLog(value = "分页列表查询")
    @ApiOperation(value="分页列表查询", notes="分页列表查询")
    @GetMapping(value = "/list")
    public Result<?> queryPageList(StmDistributorGroup stmDistributorGroup,
                                   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                   HttpServletRequest req) {
        QueryWrapper<StmDistributorGroup> queryWrapper = QueryGenerator.initQueryWrapper(stmDistributorGroup, req.getParameterMap());
        queryWrapper.eq("status", 1);
        Page<StmDistributorGroup> page = new Page<StmDistributorGroup>(pageNo, pageSize);
        IPage<StmDistributorGroup> pageList = distributorGroupService.page(page, queryWrapper);

        return Result.ok(pageList);
    }



}
